package com.point.ootb.controller;

import com.point.ootb.core.ResponseResult;
import com.point.ootb.domain.dto.LoginDTO;
import com.point.ootb.domain.dto.RegisterDTO;
import com.point.ootb.domain.vo.LoginUserInfoVO;
import com.point.ootb.service.ILoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "登录管理控制器", tags = {"登录"})
@RequestMapping("/system/user")
@RequiredArgsConstructor
@Validated
public class LoginController {

    private final ILoginService loginService;

    @PostMapping("/login")
    @ApiOperation("登录")
    public ResponseResult<String> login(@RequestBody LoginDTO loginDTO){
        return ResponseResult.ok(loginService.login(loginDTO));
    }

    @PostMapping("/register")
    @ApiOperation("注册")
    public ResponseResult<String> register(@RequestBody RegisterDTO registerDTO){
        loginService.register(registerDTO);
        return ResponseResult.ok();
    }

    @GetMapping("/info")
    @ApiOperation("获取当前登录用户信息")
    public ResponseResult<LoginUserInfoVO> info(){
        return ResponseResult.ok(loginService.getLoginUserInfo());
    }
}
